<?php

/**
 * This is the model class for table "ingatlan".
 *
 * The followings are the available columns in table 'ingatlan':
 * @property string $ID
 * @property string $ingatlan_tipus_ID
 * @property string $varos_ID
 * @property integer $publikus
 * @property string $eladva
 * @property string $cim
 * @property string $iranyitoszam
 * @property string $ar
 * @property string $leiras
 * @property string $ingatlanTipusNev
 * @property string $varosNev
 *
 * The followings are the available model relations:
 * @property IngatlanTipus $ingatlanTipus
 * @property Varos $varos
 * @property IngatlanJellemzo[] $ingatlanJellemzos
 * @property IngatlanKategoria[] $ingatlanKategorias
 * @property IngatlanKepek[] $ingatlanKepeks
 */
class BaseIngatlan extends CActiveRecord {

    /**
     *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     * Ezeket én írtam!!!
     */
    public $ingatlanTipusNev;
    public $varosNev;

    /**
     * Itt lehet megadni az osztályhoz tartozó behavior-okat és ez a metódus 
     * visszaadja azok tömbjét.
     * @return array Az osztályhoz tartozó bahavior-ok tömbje.
     */
    public function behaviors() {

        return array(
            'LogicalDeleteBehavior',
        );
    }

    public function setIngatlanTipusNev() {
        $record = IngatlanTipus::model()->findByPk($this->ingatlan_tipus_ID);
        $this->ingatlanTipusNev = $record->tipus_nev;
    }

    public function setVarosNev() {
        $this->varosNev = $this->varos->varos_nev;
    }
    /**
     * idáig!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     */
    
    
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Ingatlan the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'ingatlan';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('ingatlan_tipus_ID, varos_ID, eladva', 'required'),
            array('publikus, ar', 'numerical', 'integerOnly' => true),
            array('ingatlan_tipus_ID, varos_ID', 'length', 'max' => 10),
            array('eladva', 'length', 'max' => 1),
            array('ar', 'length', 'max' => 15),
            array('iranyitoszam', 'length', 'max' => 10),
            array('cim', 'length', 'max' => 45),
            array('leiras', 'length', 'max' => 10000),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('ID, ingatlan_tipus_ID, varos_ID, publikus, eladva, cim, iranyitoszam, ar, leiras', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'ingatlanTipus' => array(self::BELONGS_TO, 'IngatlanTipus', 'ingatlan_tipus_ID'),
            'varos' => array(self::BELONGS_TO, 'Varos', 'varos_ID'),
            'ingatlanJellemzos' => array(self::MANY_MANY, 'IngatlanJellemzo', 'ingatlan_has_ingatlan_jellmzo(ingatlan_ID, ingatlan_jellmzo_ID)'),
            'ingatlanKategorias' => array(self::MANY_MANY, 'IngatlanKategoria', 'ingatlan_has_ingatlan_kategoria(ingatlan_ID, ingatlan_kategoria_ID)'),
            'ingatlanKepeks' => array(self::HAS_MANY, 'IngatlanKepek', 'ingatlan_ID'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'ID' => 'ID',
            'ingatlan_tipus_ID' => 'Ingatlan Tipus_ID',
            'varos_ID' => 'Varos_ID',
            'publikus' => 'Publikus',
            'eladva' => 'Eladva',
            'cim' => 'Cim',
            'iranyitoszam' => 'Iranyitoszam',
            'ar' => 'Ar',
            'leiras' => 'Leiras',
            'varosNev' => 'Város',
            'ingatlanTipusNev' => 'Ingatlan Típus',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('ID', $this->ID, true);
        $criteria->compare('ingatlan_tipus_ID', $this->ingatlan_tipus_ID, true);
        $criteria->compare('varos_ID', $this->varos_ID, true);
        $criteria->compare('publikus', $this->publikus);
        $criteria->compare('eladva', $this->eladva, true);
        $criteria->compare('cim', $this->cim, true);
        $criteria->compare('iranyitoszam', $this->iranyitoszam, true);
        $criteria->compare('ar', $this->ar, true);
        $criteria->compare('leiras', $this->leiras, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
                ));
    }

}